function promiseAll(promises) {
  return new Promise(function (resolve, reject) {
    if (!Array.isArray(promises)) {
      throw new TypeError("argument must be a array");
    }
    var resolveCounter = 0;
    var promiseNum = promises.length;
    var resolvedResult = [];
    for (let i = 0; i < promiseNum; i++) {
      Promise.resolve(promises[i]).then(
        (value) => {
          resolveCounter++;
          resolvedResult[i] = value;
          if (resolveCounter === promiseNum) {
            return resolve(resolvedResult);
          }
        },
        (error) => {
          return reject(error);
        }
      )
    }
  });
}


//test
let p1=new Promise(function(resolve,reject){
  setTimeout(function(){
    resolve(1);
  },1000)
})
let p2=new Promise(function(resolve,reject){
  setTimeout(function(){
   resolve(2);
  },2000)
})
let p3=new Promise(function(resolve,reject){
  setTimeout(function(){
    resolve(3);
  },3000)
})

promiseAll([p1,p2,p2]).then(res=>{
  console.log(res);
})

let arr =[{a:1}]
let arrb=arr.slice(0)
arrb[0].a=2
console.log(arr[0].a);//2

let ggg=[1,2,3,4]
let clone=ggg.slice(0)
clone.push(888)
console.log(ggg);
console.log(clone,'clone');